/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * input.java
 *
 * Created on Oct 26, 2011, 6:30:53 AM
 */
package irsystem;

import com.sun.media.ui.MessageBox;
import irsystem.collection.CISI;
import irsystem.scenario.*;
import irsystem.scenario.method.TermVectorSpace;
import java.awt.Dialog;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author cas
 */
public class input extends javax.swing.JFrame {

    /** Creates new form input */
    public input(){
        initComponents();
    }
    
    boolean stem;
    boolean stopword;
    int tf;
    boolean idf;
    boolean normal;
    ScenarioOption sc;
    TermVectorSpace result;
    /*
     * a = stemming
     * b = stopword
     * c = 0 -> raw tf
     * c = 1 -> binary tf
     * c = 2 -> logaritmik tf
     * c = 3 -> augmented tf
     * d = idf
     * e = normal
     */
    public input(boolean a, boolean b, int c, boolean d, boolean e){
        initComponents();
        stem = a;stopword = b;tf = c;idf = d;normal = e;
    }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        judul = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        doc = new javax.swing.JTextField();
        rel = new javax.swing.JTextField();
        query = new javax.swing.JTextField();
        stop = new javax.swing.JTextField();
        docOpen = new javax.swing.JButton();
        relOpen = new javax.swing.JButton();
        stopOpen = new javax.swing.JButton();
        queryOpen = new javax.swing.JButton();
        cari = new javax.swing.JButton();
        eksperimen = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        inverted = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        invertFile = new javax.swing.JTextField();
        invertedOpen = new javax.swing.JButton();
        generate = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        judul.setFont(new java.awt.Font("Tahoma", 0, 18));
        judul.setText("not MAUL IR System");

        jLabel1.setText("File Stopword");

        jLabel2.setText("Document Collections");

        jLabel3.setText("Relevance Judgement");

        jLabel4.setText("Query");

        doc.setEditable(false);

        rel.setEditable(false);

        query.setEditable(false);

        stop.setEditable(false);

        docOpen.setText("Open");
        docOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                docOpenActionPerformed(evt);
            }
        });

        relOpen.setText("Open");
        relOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relOpenActionPerformed(evt);
            }
        });

        stopOpen.setText("Open");
        stopOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopOpenActionPerformed(evt);
            }
        });

        queryOpen.setText("Open");
        queryOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                queryOpenActionPerformed(evt);
            }
        });

        cari.setText("Pencarian");
        cari.setMaximumSize(new java.awt.Dimension(87, 25));
        cari.setMinimumSize(new java.awt.Dimension(87, 25));
        cari.setPreferredSize(new java.awt.Dimension(87, 23));
        cari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cariActionPerformed(evt);
            }
        });

        eksperimen.setText("Eksperimen");
        eksperimen.setMaximumSize(new java.awt.Dimension(87, 25));
        eksperimen.setMinimumSize(new java.awt.Dimension(87, 25));
        eksperimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eksperimenActionPerformed(evt);
            }
        });

        inverted.setColumns(20);
        inverted.setEditable(false);
        inverted.setRows(5);
        jScrollPane1.setViewportView(inverted);

        jLabel6.setText("Inverted File");

        invertFile.setEditable(false);

        invertedOpen.setText("Open");
        invertedOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                invertedOpenActionPerformed(evt);
            }
        });

        generate.setText("Generate");
        generate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 521, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(doc, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                            .addComponent(stop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                            .addComponent(rel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                            .addComponent(query, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(invertFile, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(invertedOpen, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(judul, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(460, 460, 460)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(relOpen, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                    .addComponent(docOpen, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                    .addComponent(stopOpen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                    .addComponent(cari, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                    .addComponent(eksperimen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(generate, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                    .addComponent(queryOpen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(judul, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(doc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(docOpen))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(rel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(relOpen))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(stop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(stopOpen))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(query, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(queryOpen))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(invertFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(invertedOpen)
                    .addComponent(generate, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(eksperimen, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cari, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void docOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_docOpenActionPerformed
// TODO add your handling code here:
    JFileChooser fc = new JFileChooser();

    int retval = fc.showOpenDialog(input.this);

    if (retval == JFileChooser.APPROVE_OPTION){
        File file = fc.getSelectedFile();

        doc.setText(file.toString());
    }
}//GEN-LAST:event_docOpenActionPerformed

private void relOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relOpenActionPerformed
// TODO add your handling code here:
    JFileChooser fc = new JFileChooser();

    int retval = fc.showOpenDialog(input.this);

    if (retval == JFileChooser.APPROVE_OPTION){
        File file = fc.getSelectedFile();

        rel.setText(file.toString());
    }
}//GEN-LAST:event_relOpenActionPerformed

private void stopOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopOpenActionPerformed
// TODO add your handling code here:
    JFileChooser fc = new JFileChooser();

    int retval = fc.showOpenDialog(input.this);

    if (retval == JFileChooser.APPROVE_OPTION){
        File file = fc.getSelectedFile();
        stop.setText(file.toString());
    }
}//GEN-LAST:event_stopOpenActionPerformed

private void queryOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queryOpenActionPerformed
// TODO add your handling code here:
    JFileChooser fc = new JFileChooser();

    int retval = fc.showOpenDialog(input.this);

    if (retval == JFileChooser.APPROVE_OPTION){
        File file = fc.getSelectedFile();
        query.setText(file.toString());
    }
}//GEN-LAST:event_queryOpenActionPerformed

private void eksperimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eksperimenActionPerformed
// TODO add your handling code here:
    dispose();
    ScenarioOption sc = new ScenarioOption(stem, stopword, tf, idf, normal);
    try {
        CISI cisi = CISI.readFromFiles(doc.getText(), rel.getText(), query.getText(), stop.getText());
        eksperimen eksp = new eksperimen(sc, cisi);
        eksp.setVisible(true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(input.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(input.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_eksperimenActionPerformed

private void cariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cariActionPerformed
// TODO add your handling code here:
    dispose();
    ScenarioOption sc = new ScenarioOption(stem, stopword, tf, idf, normal);
    try {
        CISI cisi = CISI.readFromFiles(doc.getText(), rel.getText(), query.getText(), stop.getText());
        pencarian newpencarian = new pencarian(sc,cisi);
        newpencarian.setVisible(true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(input.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(input.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_cariActionPerformed

private void invertedOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invertedOpenActionPerformed
// TODO add your handling code here:
    JFileChooser fc = new JFileChooser();
    
    int retval = fc.showOpenDialog(input.this);

    if (retval == JFileChooser.APPROVE_OPTION){
        File file = fc.getSelectedFile();
        invertFile.setText(file.toString());
    }
}//GEN-LAST:event_invertedOpenActionPerformed

private void generateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateActionPerformed
// TODO add your handling code here:
    
    if (doc.getText().equals("")&&rel.getText().equals("")&&query.getText().equals("")&&stop.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Semua File Harus Diinputkan", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
            try {
                sc = new ScenarioOption(stem, stopword, tf, idf, normal);
                CISI cisi = CISI.readFromFiles(doc.getText(), rel.getText(), query.getText(), stop.getText());
                Experiment exp = new Experiment(sc, cisi);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(input.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(input.class.getName()).log(Level.SEVERE, null, ex);
            }
        
    }
}//GEN-LAST:event_generateActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new input(true,true,0,true,true).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cari;
    private javax.swing.JTextField doc;
    private javax.swing.JButton docOpen;
    private javax.swing.JButton eksperimen;
    private javax.swing.JButton generate;
    private javax.swing.JTextField invertFile;
    private javax.swing.JTextArea inverted;
    private javax.swing.JButton invertedOpen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel judul;
    private javax.swing.JTextField query;
    private javax.swing.JButton queryOpen;
    private javax.swing.JTextField rel;
    private javax.swing.JButton relOpen;
    private javax.swing.JTextField stop;
    private javax.swing.JButton stopOpen;
    // End of variables declaration//GEN-END:variables
}
